package com.anolesoft.yr.mbus.pre.mapper;

import com.anolesoft.yr.mbus.pre.dto.PreVisitDeleteDTO;
import com.anolesoft.yr.mbus.pre.dto.PreVisitSaveDTO;
import com.anolesoft.yr.mbus.pre.dto.PreVisitUpdateDTO;
import com.anolesoft.yr.mbus.pre.sql.PreVisitSQL;
import com.anolesoft.yr.mbus.pre.vo.PreVisitQueryVO;
import com.anolesoft.yr.mbus.pre.vo.PreVisitQueryVO2;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PreVisitMapper {

    //新增时查询拜访记录编号是否已经存在
    @Select(PreVisitSQL.QUERY_PRE_VISIT_BY_CODE)
    @Results(id="queryVisitByCode", value = {
            @Result(column = "count", property = "count")
    })
    int queryVisitByCode(String visitCode);

    //新增拜访客户记录
    @Insert(PreVisitSQL.SAVE_PRE_VISIT)
    int savePreVisit(PreVisitSaveDTO preVisitSaveDTO);

    //修改时查询拜访记录编号是否已经存在（不包含本身）
    @Select(PreVisitSQL.QUERY_PRE_VISIT_BY_CODE2)
    @Results(id = "queryVisitByCode2", value = {
            @Result(column = "count", property = "count")
    })
    int queryVisitByCode2(@Param("visitCode") String visitCode, @Param("visitCode2") String visitCode2);

    //修改拜访客户记录
    @Update(PreVisitSQL.UPDATE_PRE_VISIT)
    int updatePreVisit(PreVisitUpdateDTO preVisitUpdateDTO);

    //删除推广记录
    @Update(PreVisitSQL.DELETE_PRE_VISIT)
    int deletePreVisit(PreVisitDeleteDTO preVisitDeleteDTO);

    //根据主键查询拜访记录唯一数据
    @Select(PreVisitSQL.QUERY_PRE_VISIT_BY_UID)
    @Results(id="queryPreVisitByUid", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "visit_code", property = "updateVisitCode"),
            @Result(column = "visit_time", property = "updateVisitTime"),
            @Result(column = "client_name_", property = "updateClientName_"),
            @Result(column = "client_name", property = "updateClientName"),
            @Result(column = "client_region_", property = "updateClientRegion_"),
            @Result(column = "client_region", property = "updateClientRegion"),
            @Result(column = "contact", property = "updateContact"),
            @Result(column = "contact_person", property = "updateContactPerson"),
            @Result(column = "client_demand", property = "updateClientDemand"),
            @Result(column = "purchase_quantity", property = "updatePurchaseQuantity"),
            @Result(column = "sales_person_", property = "updateSalesPerson_"),
            @Result(column = "sales_person", property = "updateSalesPerson"),
            @Result(column = "remark", property = "updateRemark")
    })
    PreVisitQueryVO2 queryPreVisitByUid(String objuid);

    //根据条件查询拜访客户记录条数
    @Select(PreVisitSQL.QUERT_PRE_VISIT_COUNT)
    @Results(id = "queryPreVisitAllCount", value = {
            @Result(column = "count", property = "count")
    })
    int queryPreVisitAllCount(@Param("visitTime") String visitTime, @Param("clientName") String clientName, @Param("salesPerson") String salesPerson);

    //查询拜访客户记录
    @Select(PreVisitSQL.QUERT_PRE_VISIT)
    @Results(id = "queryPreVisitAll", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "visit_code", property = "visitCode"),
            @Result(column = "visit_time", property = "visitTime"),
            @Result(column = "client_name", property = "clientName"),
            @Result(column = "client_region", property = "clientRegion"),
            @Result(column = "contact", property = "contact"),
            @Result(column = "contact_person", property = "contactPerson"),
            @Result(column = "client_demand", property = "clientDemand"),
            @Result(column = "purchase_quantity", property = "purchaseQuantity"),
            @Result(column = "sales_person", property = "salesPerson"),
            @Result(column = "remark", property = "remark"),
            @Result(column = "c_user_uid", property = "ccUserUid"),
            @Result(column = "c_time", property = "ccTime")
    })
    List<PreVisitQueryVO> queryPreVisitAll(@Param("visitTime") String visitTime, @Param("clientName") String clientName, @Param("salesPerson") String salesPerson, @Param("page") int page, @Param("limit") int limit);

}
